//
//  XBAuctionArray.m
//  寻宝之旅
//
//  Created by LyuBook on 16/3/28.
//  Copyright © 2016年 lvdingze. All rights reserved.
//

#import "XBAuctionGroup.h"
#import "AFNetworking.h"
#import "MJExtension.h"
#import "XBAuction.h"
//#import "NSObject+Model.h"
@implementation XBAuctionGroup
+ (void)loadAuctionGroupseSuccess:(void (^)(NSArray *auctionGroups))success{
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];

    [mgr GET:@"http://api.xunbaozl.com/v2/post/auctionPreview2?" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray *array = responseObject[@"data"];
        //拍卖模型数组
        NSMutableArray *auctionArrayM =[NSMutableArray array];
        for (NSDictionary *dict in array) {
            XBAuctionGroup *auctionGroup = [XBAuctionGroup mj_objectWithKeyValues:dict];
//            XBAuctionGroup *auctionGroup = [XBAuctionGroup objectWithDictioanary:dict];
            auctionGroup.auctions = [XBAuction mj_objectArrayWithKeyValuesArray:auctionGroup.auctions];
//            auctionGroup.auctions = [XBAuction objectArrayWithDictArray:auctionGroup.auctions];
            [auctionArrayM addObject:auctionGroup];
            
          
        }
        XBAuctionGroup *lastObj = [auctionArrayM lastObject];
        NSMutableArray *arrM = [NSMutableArray array];
        [arrM addObject:lastObj];
        [auctionArrayM removeObject:lastObj];
        
        for (XBAuctionGroup *obj in auctionArrayM) {
            [arrM addObject:obj];
        }
        success(arrM.copy);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];

}
@end
